// Copyright (C) 2024 Kumo inc.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#pragma once

#include <cstddef>

namespace deneb {

/// Stores statistics for a single key.
///
/// The statistics stored are the total number of hits and the total number of
/// misses. The total number of acccesses (the sum of hits and misses) may be
/// accessed as well.
struct KeyStatistics {
  using size_t = std::size_t;

  /// Constructor.
  ///
  /// \param hits_ The initial number of hits for the key.
  /// \param misses_ The initial number of misses for the key.
  explicit KeyStatistics(size_t hits_ = 0, size_t misses_ = 0)
  : hits(hits_), misses(misses_) {
  }

  /// \returns The total number of accesses made for the key.
  /// \details This is the sum of the hits and misses.
  size_t accesses() const noexcept {
    return hits + misses;
  }

  /// Resets the statistics for a key (sets them to zero).
  void reset() {
    hits = 0;
    misses = 0;
  }

  /// The number of hits for the key.
  size_t hits;

  /// The number of misses for the key.
  size_t misses;
};

}  // namespace deneb

